﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using SGP;
using System.Security.Cryptography;
using System.Xml;

namespace ParticleEditor
{




    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
            SGP.ManagedDirect3D.Instance.InitManagedDirect3D(Panel1, true);
            SGP.ManagedTextureManager.Instance.InitManagedTextureManager(SGP.ManagedDirect3D.Instance.Device, SGP.ManagedDirect3D.Instance.Sprite);
            SGP.ManagedDirect3D.Instance.ChangeDisplayParam(Panel1);
            TheOne.m_strName = "../../MLB_Target2.png";
    int testing =SGP.ManagedTextureManager.Instance.LoadTexture(TheOne.m_strName, Color.FromArgb(0, 0, 0, 0).ToArgb());
    if (testing == -1)
    {
        while (testing == -1)
        {
            openFileDialog1.ShowDialog();
            TheOne.m_strName = openFileDialog1.SafeFileName;
            testing = SGP.ManagedTextureManager.Instance.LoadTexture(TheOne.m_strName, Color.FromArgb(0, 0, 0, 0).ToArgb());
        }
    }
        TheOne.m_nImageIDs = testing;

            BlendD.SelectedIndex = 1;
            BlendS.SelectedIndex = 2;
            TheOne.Starts();
        }


        public bool Looping = true;
        public bool stra = true;
        public string lockes = "../myXmFile.xml";
        public string FileNamed = "../../MLb_Target2.png";

        public Emitter TheOne = new Emitter();

        public void Updater()
        {
                //OUT();
                    
          for (int i = 0; i < TheOne.listed.Count ; i++)
          {
              Particles temp = TheOne.listed[i];
              float vx=  TheOne.listed[i].m_fX;
              float vy=  TheOne.listed[i].m_fY;
              float vxc=   TheOne.listed[i].m_fVelX_Current/10000;
              float vyc=  TheOne.listed[i].m_fVelY_Current/10000;
              float xx =  vx+vxc;
              if (xx > 400 || xx < -1)
                  xx = TheOne.m_nPosX;
              float yy = vy + vyc;
              if(yy>500||yy<-1)
                  yy = TheOne.m_nPosY;

              float cae,rae,gae,bae;

                  cae = TheOne.listed[i].m_fColorA_Current +TheOne.listed[i].m_fColorA_COT/1000;
                  rae = TheOne.listed[i].m_fColorR_Current + TheOne.listed[i].m_fColorR_COT/1000;
                  gae = TheOne.listed[i].m_fColorG_Current + TheOne.listed[i].m_fColorG_COT/1000;
                  bae = TheOne.listed[i].m_fColorB_Current + TheOne.listed[i].m_fColorB_COT/1000;
              temp.m_fColorA_Current = cae;
              temp.m_fColorB_Current = bae;
              temp.m_fColorG_Current = gae;
              temp.m_fColorR_Current = rae;

              temp.m_fX = (xx);
              temp.m_fY = (yy);

              float current = temp.m_fLife_Current;
              
              float lifes = (current - 1);
              if (lifes >= 0)
                  temp.m_fLife_Current = (lifes);
              else
                  temp.m_fLife_Current = 0;

                  if (temp.m_fLife_Current <= 0)
                      temp.m_fLife_Current = TheOne.m_nLife_Max;
              
              TheOne.listed[i] = temp;         
              }
            
         //TheOne.Starts();

        }

        public void Render()
        { 
            SGP.ManagedDirect3D.Instance.Clear(Color.White);
            SGP.ManagedDirect3D.Instance.DeviceBegin();
            SGP.ManagedDirect3D.Instance.SpriteBegin();
          
           
            for (int i = 0; i < TheOne.listed.Count; i++)
            {
                int VA=(int)TheOne.listed[i].m_fColorA_Current;
                int VR=(int)TheOne.listed[i].m_fColorR_Current;
                int VG=(int)TheOne.listed[i].m_fColorG_Current;
                int VB=(int)TheOne.listed[i].m_fColorB_Current;
                if (VA > 255) VA = 255; if (VA <0) VA = 0;
                if (VR > 255) VR = 255; if (VR <0) VR = 0;
                if (VG > 255) VG = 255; if (VG <0) VG = 0;
                if (VB > 255) VB = 255; if (VB <0) VB = 0;


                Color Thisone =Color.FromArgb(VA,VR,VG,VB);
                Rectangle thatone = Rectangle.Empty;
                thatone.Height=TheOne.m_nH;
                thatone.Width=TheOne.m_nW;
                thatone.X = (int)TheOne.listed[i].m_fX;
                thatone.Y = (int)TheOne.listed[i].m_fY;
                 
                if(TheOne.listed[i].m_fLife_Current!=0)
                SGP.ManagedTextureManager.Instance.Draw(TheOne.m_nImageIDs, thatone.X, thatone.Y, TheOne.listed[i].m_fScaleX_Current, TheOne.listed[i].m_fScaleY_Current, Rectangle.Empty, TheOne.m_nImageX / 2, TheOne.m_nImageY / 2, 0, Thisone);
                

            }
            
            
            SGP.ManagedDirect3D.Instance.SpriteEnd();
            SGP.ManagedDirect3D.Instance.DeviceEnd();
            SGP.ManagedDirect3D.Instance.Present(Panel1);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();
            StartRed.Value  =colorDialog1.Color.R;
            StartGreen.Value=colorDialog1.Color.G;
            StartBlue.Value =colorDialog1.Color.B;
            StartAlpha.Value=colorDialog1.Color.A;
                        int vred =   (int)StartRed.Value  ;
                        int vgreen = (int)StartGreen.Value;
                        int vblue =  (int)StartBlue.Value ;
                        int valpha = (int)StartAlpha.Value;
                        Colorpanel1.BackColor = Color.FromArgb(valpha, vred, vgreen, vblue);
                           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            colorDialog2.ShowDialog();
           // sender.Colorpanel2_Paint(sender,e);
            EndRed.Value=   colorDialog2.Color.R;
            EndGreen.Value= colorDialog2.Color.G;
            EndBlue.Value=  colorDialog2.Color.B;
            EndAlpha.Value= colorDialog2.Color.A;
            int vred = ((int)EndRed.Value);
            int vgreen = ((int)EndRed.Value);
            int vblue = ((int)EndRed.Value);
            int valpha = ((int)EndRed.Value);
            Colorpanel2.BackColor =Color.FromArgb(valpha,vred,vgreen,vblue);

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Looping = false;
        }

        public void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            //System.Security.Cryptography.RandomNumberGenerator.Create();
            byte[] rando = new byte[33];
            int[] bob = new int[33];
            RandomNumberGenerator numberGenerator = System.Security.Cryptography.RandomNumberGenerator.Create();
            numberGenerator.GetNonZeroBytes(rando);
            for (int q = 0; q < 33; q++)
            {
                bob[q]=rando[q];
            }

           // Random(DateTime.Today.Millisecond);
            if (CBRS.Checked == true)
            {
                StartRed.Value = new Random(bob[0]).Next(1, 255);
            }
            if (CBGS.Checked == true)
           StartGreen.Value =  new Random(bob[1]).Next(1,255);
            if (CBBS.Checked == true)
           StartBlue.Value  =  new Random(bob[2]).Next(1,255);
            if (CBAS.Checked == true)
           StartAlpha.Value =  new Random(bob[3]).Next(1,255);
            if (CBRE.Checked == true)
           EndRed.Value     =  new Random(bob[4]).Next(1,255);
            if (CBGE.Checked == true)
           EndGreen.Value   =  new Random(bob[5]).Next(1,255);
            if (CBBE.Checked == true)
           EndBlue.Value    =  new Random(bob[6]).Next(1,255);
            if (CBAE.Checked == true)
           EndAlpha.Value   =  new Random(bob[7]).Next(1,255);
            
            if (CBX.Checked == true)
           NUDx.Value = new Random(bob[8]).Next(1,300);
            if (CBY.Checked == true)
           NUDy.Value = new Random(bob[9]).Next(1,400);
            if (CBW.Checked == true)
           NUDw.Value = new Random(bob[10]).Next(1,500);
            if (CBH.Checked == true)
           NUDh.Value = new Random(bob[11]).Next(1,500);

            if (CBSXS.Checked == true)
           NUDscaleXStart.Value   =  new Random(bob[12]).Next(1,100);
            if (CBSYS.Checked == true)
           NUDscaleYStart.Value   =  new Random(bob[13]).Next(1,100);
            if (CBSXE.Checked == true)
           NUDscaleXEnd.Value     =  new Random(bob[14]).Next(1,100);
            if (CBSYE.Checked == true)
            NUDscaleYEnd.Value     =  new Random(bob[15]).Next(1, 100);
            if (CBLmi.Checked == true)
           NUDLife.Value =         new Random(bob[16]).Next(1, 100);
            if (CBMP.Checked == true)
           NUDMaxParticles.Value = new Random(bob[17]).Next(1, 100);
            if (CBLMa.Checked == true)
            {
                int ea = (int)NUDLife.Value+1;
                NUBLife2.Value = new Random(bob[31]).Next(ea, 100);
            }
            if (CBSR.Checked == true)
            {
                decimal Workfiled = (new Random(bob[18]).Next(5, 500));
                if (Workfiled == 0)
                    NUDspawnrate.Value = Workfiled;
                else
                    NUDspawnrate.Value = Workfiled / 100;
            }
            if (CBR.Checked == true)
           NUDroto.Value =         new Random(bob[19]).Next(1, 360);
            if (CBSB.Checked == true)
           BlendS.SelectedIndex = new Random(bob[20]).Next(1, 17);
            if (CBDB.Checked == true)
           BlendD.SelectedIndex = new Random(bob[21]).Next(1, 17);
            if (CBVXSMi.Checked == true)
           NUD_XSMi.Value = new Random(bob[22]).Next(-1000,1000);
            if (CBVXSMa.Checked == true)
            {
                int ea = (int)NUD_XSMi.Value;
                NUD_XSMa.Value = new Random(bob[23]).Next(ea, 1000);
            }
            if (CBVXEMi.Checked == true)
           NUD_XEMi.Value = new Random(bob[24]).Next(-1000,1000);
            if (CBVXEMa.Checked == true)
            {
                int ea = (int)NUD_XEMi.Value;
                NUD_XEMa.Value = new Random(bob[25]).Next(ea, 1000);
            }
            if (CBVYSMi.Checked == true)
                NUD_YSMi.Value = new Random(bob[27]).Next(-1000, 1000);
            if (CBVYSMa.Checked == true)
            {
                int ea = (int)NUD_YSMi.Value;
                NUD_YSMa.Value = new Random(bob[28]).Next(ea, 1000);
            }
            if (CBVYEMi.Checked == true)
           NUD_YEMi.Value = new Random(bob[29]).Next(-1000,1000);
            if (CBVYEMa.Checked == true)
            {
                int ea = (int)NUD_YEMi.Value;
                NUD_YEMa.Value = new Random(bob[30]).Next(ea, 1000);
            }
           SetAll();
           
        }

        private void StartRed_ValueChanged(object sender, EventArgs e)
        {
            int vred = (int)StartRed.Value;
            int vgreen = (int)StartGreen.Value;
            int vblue = (int)StartBlue.Value;
            int valpha = (int)StartAlpha.Value;
            Colorpanel1.BackColor = Color.FromArgb(valpha, vred, vgreen, vblue);
            SetAll();


        }

        private void StartGreen_ValueChanged(object sender, EventArgs e)
        {
            int vred = (int)StartRed.Value;
            int vgreen = (int)StartGreen.Value;
            int vblue = (int)StartBlue.Value;
            int valpha = (int)StartAlpha.Value;
            Colorpanel1.BackColor = Color.FromArgb(valpha, vred, vgreen, vblue);
            SetAll();

        }

        private void StartBlue_ValueChanged(object sender, EventArgs e)
        {
            int vred = (int)StartRed.Value;
            int vgreen = (int)StartGreen.Value;
            int vblue = (int)StartBlue.Value;
            int valpha = (int)StartAlpha.Value;
            Colorpanel1.BackColor = Color.FromArgb(valpha, vred, vgreen, vblue);
            SetAll();
        }

        private void StartAlpha_ValueChanged(object sender, EventArgs e)
        {
            int vred = (int)StartRed.Value;
            int vgreen = (int)StartGreen.Value;
            int vblue = (int)StartBlue.Value;
            int valpha = (int)StartAlpha.Value;
            Colorpanel1.BackColor = Color.FromArgb(valpha, vred, vgreen, vblue);
            SetAll();
        }

        private void EndRed_ValueChanged(object sender, EventArgs e)
        {
            int vred =   ((int)EndRed.Value) ;
            int vgreen = ((int)EndGreen.Value);
            int vblue =  ((int)EndBlue.Value) ;
            int valpha = ((int)EndAlpha.Value);
            Colorpanel2.BackColor = Color.FromArgb(valpha, vred, vgreen, vblue);
            SetAll();
        }

        private void EndGreen_ValueChanged(object sender, EventArgs e)
        {
            int vred = ((int)EndRed.Value);
            int vgreen = ((int)EndGreen.Value);
            int vblue = ((int)EndBlue.Value);
            int valpha = ((int)EndAlpha.Value);
            Colorpanel2.BackColor = Color.FromArgb(valpha, vred, vgreen, vblue);
            SetAll();
        }

        private void EndBlue_ValueChanged(object sender, EventArgs e)
        {
            int vred = ((int)EndRed.Value);
            int vgreen = ((int)EndRed.Value);
            int vblue = ((int)EndRed.Value);
            int valpha = ((int)EndRed.Value);
            Colorpanel2.BackColor = Color.FromArgb(valpha, vred, vgreen, vblue);
            SetAll();
        }

        private void EndAlpha_ValueChanged(object sender, EventArgs e)
        {
            int vred = ((int)EndRed.Value);
            int vgreen = ((int)EndGreen.Value);
            int vblue = ((int)EndBlue.Value);
            int valpha = ((int)EndAlpha.Value);
            Colorpanel2.BackColor = Color.FromArgb(valpha, vred, vgreen, vblue);
            SetAll();

        }

        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            FileNamed = openFileDialog1.FileName;
        }
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            saveFileDialog1.ShowDialog();
            lockes = saveFileDialog1.FileName;
            OUT();
        }
        private void saveToolStripMenuItem_FileOk(object sender, EventArgs e)
        {
            lockes = saveFileDialog1.FileName;
        }
        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            FileNamed = openFileDialog1.SafeFileName;
        }

        private void LoadImage_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
        }

        public void SetAll()
        {



            this.TheOne.m_nPosX = (int)NUDx.Value;
            this.TheOne.m_nPosY = (int)NUDy.Value;
            this.TheOne.m_fSpawnRate = (float)NUDspawnrate.Value;
            this.TheOne.m_fScaleX_Start = (float)NUDscaleXStart.Value;
            this.TheOne.m_fScaleX_End = (float)NUDscaleXEnd.Value;
            this.TheOne.m_fScaleY_Start = (float)NUDscaleYStart.Value;
            this.TheOne.m_fScaleY_End = (float)NUDscaleYEnd.Value;
            this.TheOne.m_fColorR_Start = (float)StartRed.Value;
            this.TheOne.m_fColorR_End = (float)EndRed.Value;
            this.TheOne.m_fColorG_Start = (float)StartGreen.Value;
            this.TheOne.m_fColorG_End = (float)EndGreen.Value;
            this.TheOne.m_fColorB_Start = (float)StartBlue.Value;
            this.TheOne.m_fColorB_End = (float)EndBlue.Value;
            this.TheOne.m_fColorA_Start = (float)StartAlpha.Value;
            this.TheOne.m_fColorA_End = (float)EndAlpha.Value;
            this.TheOne.m_fVelXS2 = (float)NUD_XSMi.Value;
            this.TheOne.m_fVelXS  = (float)NUD_XSMa.Value;
            this.TheOne.m_fVelXE2= (float)NUD_XEMi.Value;
            this.TheOne.m_fVelXE  = (float)NUD_XEMa.Value;
            this.TheOne.m_fVelYS2= (float)NUD_YSMi.Value;
            this.TheOne.m_fVelYS  = (float)NUD_YSMa.Value;
            this.TheOne.m_fVelYE2= (float)NUD_YEMi.Value;
            this.TheOne.m_fVelYE = (float)NUD_YEMa.Value;
            this.TheOne.m_fRotation_Start = 0;
            this.TheOne.m_fRotation_End = (float)NUDroto.Value;
            this.TheOne.m_strName = FileNamed;
            this.TheOne.m_bLooping = checkBox1.Checked;
            this.TheOne.m_nLife_Max = (int)NUDLife.Value;
            this.TheOne.m_nLife_Min = (int)(NUDLife.Value / 2);
            this.TheOne.m_nMaxParticles = (int)NUDMaxParticles.Value;
            this.TheOne.m_nSourceBlend = (int)BlendS.SelectedIndex;
            this.TheOne.m_nDestBlend = (int)BlendD.SelectedIndex;
            this.TheOne.m_nImageX = 32;
            this.TheOne.m_nImageY = 32;
            this.TheOne.m_nH = (int)NUDw.Value;
            this.TheOne.m_nW = (int)NUDh.Value;
            this.TheOne.m_nRTop = (int)(NUDy.Value);
            this.TheOne.m_nRBottom = (int)(NUDh.Value + NUDy.Value);
            this.TheOne.m_nRLeft = (int)(NUDx.Value);
            this.TheOne.m_nRRight = (int)(NUDw.Value+ NUDx.Value);
            
            for (int i = 0; i < TheOne.listed.Count; i++)
            {
                Particles temp = TheOne.listed[i];
                byte[] rando = new byte[20];
                int[] bob = new int[20];
                RandomNumberGenerator numberGenerator = System.Security.Cryptography.RandomNumberGenerator.Create();
                numberGenerator.GetNonZeroBytes(rando);
                for (int q = 0; q < 20; q++)
                {
                    bob[q] = rando[q];
                }


                int vsx = (int)(TheOne.m_fVelXS); int vsx2 = (int)(TheOne.m_fVelXS2);
                int vex = (int)(TheOne.m_fVelXE); int vex2 = (int)(TheOne.m_fVelXE2);
                int vsy = (int)(TheOne.m_fVelYS); int vsy2 = (int)(TheOne.m_fVelYS2);
                int vey = (int)(TheOne.m_fVelYE); int vey2 = (int)(TheOne.m_fVelYE2);

               temp.m_fX = (float)TheOne.m_nPosX ;
               temp.m_fY=( (float)TheOne.m_nPosY );

               temp.m_fLife_Current = new Random(bob[0]).Next(TheOne.m_nLife_Min, TheOne.m_nLife_Max);
               if (vex < vex2)
                   vex = vex2 + 1;
               temp.m_fVelX_End = new Random(bob[1]).Next(vex2, vex);
               if (vsx < vsx2)
                   vsx = vsx2 + 1;
               temp.m_fVelX_Current = new Random(bob[2]).Next(vsx2, vsx);
               if (vey < vey2)
                   vey = vey2 + 1;
               temp.m_fVelY_End = new Random(bob[3]).Next(vey2, vey);
               if (vsy < vsy2)
                   vsy = vsy2 + 1;
               temp.m_fVelY_Current = new Random(bob[4]).Next(vsy2, vsy);

               temp.m_fVelX_VOT=((TheOne.m_fVelXE - TheOne.m_fVelXS) / temp.m_fLife_Current );
               temp.m_fVelY_VOT = ((TheOne.m_fVelYE - TheOne.m_fVelYS) / temp.m_fLife_Current);
               temp.m_fScaleX_Current=(TheOne.m_fScaleX_Start);
               temp.m_fScaleY_Current=(TheOne.m_fScaleY_Start);
               temp.m_fScaleX_End=(TheOne.m_fScaleX_End);
               temp.m_fScaleY_End=(TheOne.m_fScaleY_End);
               temp.m_fScaleX_SOT=((TheOne.m_fScaleX_End - TheOne.m_fScaleX_Start) / TheOne.m_nLife_Max);
               temp.m_fScaleY_SOT=((TheOne.m_fScaleY_End - TheOne.m_fScaleY_Start) / TheOne.m_nLife_Max);
               temp.m_fRotation_Current=(TheOne.m_fRotation_Start);
               temp.m_fRotation_End=(TheOne.m_fRotation_End);
               temp.m_fRotation_ROT=((TheOne.m_fRotation_End - TheOne.m_fRotation_Start) / TheOne.m_nLife_Max);
               temp.m_fColorR_Current=(TheOne.m_fColorR_Start);
               temp.m_fColorR_End=(TheOne.m_fColorR_End);
               temp.m_fColorG_Current=(TheOne.m_fColorG_Start);
               temp.m_fColorG_End=(TheOne.m_fColorG_End);
               temp.m_fColorB_Current=(TheOne.m_fColorB_Start);
               temp.m_fColorB_End=(TheOne.m_fColorB_End);
               temp.m_fColorA_Current=(TheOne.m_fColorA_Start);
               temp.m_fColorA_End=(TheOne.m_fColorA_End);
               temp.m_fColorR_COT=((TheOne.m_fColorR_End - TheOne.m_fColorR_Start) / TheOne.m_nLife_Max);
               temp.m_fColorG_COT=((TheOne.m_fColorG_End - TheOne.m_fColorG_Start) / TheOne.m_nLife_Max);
               temp.m_fColorB_COT=((TheOne.m_fColorB_End - TheOne.m_fColorB_Start) / TheOne.m_nLife_Max);
               temp.m_fColorA_COT=((TheOne.m_fColorA_End - TheOne.m_fColorA_Start) / TheOne.m_nLife_Max);


               TheOne.listed[i] = temp;


            }
            

        }
        //setters
        private void NUDx_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUDh_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUDy_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUDw_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUDscaleXStart_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUDscaleXEnd_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUDscaleYStart_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUDscaleYEnd_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUDLife_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUDMaxParticles_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUDspawnrate_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUDroto_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUD_XSMi_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUD_XSMa_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUD_XEMi_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUD_YSMi_ValueChanged(object sender, EventArgs e)
        {
            SetAll();

        }
        private void NUD_YEMi_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUD_XEMa_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUD_YSMa_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void NUD_YEMa_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void BlendS_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void BlendD_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetAll();
        }
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
        }

        public  void OUT()
        {
         //   StreamWriter writer = new StreamWriter(lockes);

            XmlTextWriter textWriter = new XmlTextWriter(lockes, System.Text.Encoding.UTF8);
            textWriter.WriteStartDocument();
            
            //<?xml version="1,0" encoding="utf-8" ?>
            //<particle_list>
            //<particle_info

            textWriter.WriteStartElement("particle_list");
            textWriter.WriteStartElement("particle_info");
            textWriter.WriteAttributeString("PosX", TheOne.m_nPosX.ToString());
            textWriter.WriteAttributeString("PosY", TheOne.m_nPosY.ToString());
            textWriter.WriteAttributeString("SpawnRate", TheOne.m_fSpawnRate.ToString());
            textWriter.WriteAttributeString("ScaleX_Start", TheOne.m_fScaleX_Start.ToString());
            textWriter.WriteAttributeString("ScaleX_End", TheOne.m_fScaleX_End.ToString());
            textWriter.WriteAttributeString("ScaleY_Start", TheOne.m_fScaleY_Start.ToString());
            textWriter.WriteAttributeString("ScaleY_End", TheOne.m_fScaleY_End.ToString());    
            textWriter.WriteAttributeString("RStart", TheOne. m_fColorR_Start.ToString());    
            textWriter.WriteAttributeString("REnd", TheOne. m_fColorR_End.ToString());    
            textWriter.WriteAttributeString("GStart", TheOne. m_fColorG_Start.ToString());    
            textWriter.WriteAttributeString("GEnd", TheOne. m_fColorG_End.ToString());    
            textWriter.WriteAttributeString("BStart", TheOne. m_fColorB_Start.ToString());    
            textWriter.WriteAttributeString("BEnd", TheOne. m_fColorB_End.ToString());    
            textWriter.WriteAttributeString("AStart", TheOne. m_fColorA_Start.ToString());    
            textWriter.WriteAttributeString("AEnd", TheOne. m_fColorA_End.ToString());
            textWriter.WriteAttributeString("VELXSTART", TheOne.m_fVelXS.ToString());
            textWriter.WriteAttributeString("VELXSTART2", TheOne.m_fVelXS2.ToString());
            textWriter.WriteAttributeString("VELXEND", TheOne.m_fVelXE.ToString());
            textWriter.WriteAttributeString("VELXEND2", TheOne.m_fVelXE2.ToString());    
            textWriter.WriteAttributeString("VELYSTART", TheOne. m_fVelYS.ToString());
            textWriter.WriteAttributeString("VELYSTART2", TheOne.m_fVelYS2.ToString());
            textWriter.WriteAttributeString("VELYEND", TheOne.m_fVelYE.ToString());
            textWriter.WriteAttributeString("VELYEND2", TheOne.m_fVelYE2.ToString());
            textWriter.WriteAttributeString("RotationStart", TheOne.m_fRotation_Start.ToString());
            textWriter.WriteAttributeString("RotationEnd", TheOne.m_fRotation_End.ToString());    
            textWriter.WriteAttributeString("STRNAME", TheOne. m_strName);   
            if(TheOne. m_bLooping ==true)
                textWriter.WriteAttributeString("Looping", "12");  
            else
                textWriter.WriteAttributeString("Looping", "0");
            if (TheOne.m_nLife_Min.Equals(1) == true || TheOne.m_nLife_Min.Equals(0) == true)
                textWriter.WriteAttributeString("Life_Max", "2");
            else
             textWriter.WriteAttributeString("Life_Max", TheOne.m_nLife_Max.ToString());
            if( TheOne.m_nLife_Min.Equals(0)==true)
                textWriter.WriteAttributeString("Life_Min", "1");
                else
            textWriter.WriteAttributeString("Life_Min", TheOne.m_nLife_Min.ToString());
            textWriter.WriteAttributeString("MaxParticles", TheOne.m_nMaxParticles.ToString());
            textWriter.WriteAttributeString("SourceBlend", TheOne.m_nSourceBlend.ToString());
            textWriter.WriteAttributeString("DestBlend", TheOne.m_nDestBlend.ToString());
            textWriter.WriteAttributeString("IX", TheOne.m_nImageX.ToString());
            textWriter.WriteAttributeString("IY", TheOne.m_nImageY.ToString());
            textWriter.WriteAttributeString("HH", TheOne.m_nH        .ToString());
            textWriter.WriteAttributeString("WW", TheOne.m_nW        .ToString()); 
            textWriter.WriteAttributeString("Top", TheOne.m_nRTop      .ToString());
            textWriter.WriteAttributeString("Bottom ", TheOne.m_nRBottom.ToString());
            textWriter.WriteAttributeString("Left ", TheOne.m_nRLeft.ToString());
            textWriter.WriteAttributeString("Right", TheOne.m_nRRight.ToString()); 




            //  textWriter.WriteStartElement("Name", "");
            //  textWriter.WriteString("dataname");
            textWriter.WriteString(FileNamed);
            textWriter.WriteEndElement();
            //>

          

            textWriter.WriteEndElement();

            //</particle_info>
            //</particle_list>
            textWriter.WriteEndDocument();
            textWriter.Close();

        }

        private void MasterCheck_CheckedChanged(object sender, EventArgs e)
        {
            if (MasterCheck.Checked == true)
            {
                CBX.Checked = true;
                CBY.Checked = true;
                CBW.Checked = true;
                CBVYSMi.Checked = true;
                CBVYSMa.Checked = true;
                CBVYEMi.Checked = true;
                CBVYEMa.Checked = true;
                CBVXSMi.Checked = true;
                CBVXSMa.Checked = true;
                CBVXEMi.Checked = true;
                CBVXEMa.Checked = true;
                CBSYS.Checked = true;
                CBSYE.Checked = true;
                CBSXE.Checked = true;
                CBSXS.Checked = true;
                CBSR.Checked = true;
                CBSB.Checked = true;
                CBRS.Checked = true;
                CBRE.Checked = true;
                CBR.Checked = true;
                CBMP.Checked = true;
                CBLmi.Checked = true;
                CBLMa.Checked = true;
                CBH.Checked = true;
                CBGS.Checked = true;
                CBGE.Checked = true;
                CBDB.Checked = true;
                CBBS.Checked = true;
                CBBE.Checked = true;
                CBAS.Checked = true;
                CBAE.Checked = true;
            }
            else
            {
                CBSXS.Checked = false;
                CBX.Checked = false;
                CBY.Checked = false;
                CBW.Checked = false;
                CBVYSMi.Checked = false;
                CBVYSMa.Checked = false;
                CBVYEMi.Checked = false;
                CBVYEMa.Checked = false;
                CBVXSMi.Checked = false;
                CBVXSMa.Checked = false;
                CBVXEMi.Checked = false;
                CBVXEMa.Checked = false;
                CBSYS.Checked = false;
                CBSYE.Checked = false;
                CBSXE.Checked = false;
                CBSR.Checked = false;
                CBSB.Checked = false;
                CBRS.Checked = false;
                CBRE.Checked = false;
                CBR.Checked = false;
                CBMP.Checked = false;
                CBLmi.Checked = false;
                CBLMa.Checked = false;
                CBH.Checked = false;
                CBGS.Checked = false;
                CBGE.Checked = false;
                CBDB.Checked = false;
                CBBS.Checked = false;
                CBBE.Checked = false;
                CBAS.Checked = false;
                CBAE.Checked = false;



            } 

        }

        private void NUBLife2_ValueChanged(object sender, EventArgs e)
        {
            SetAll();
        }







    }



}
                                                     
                                                     